package br.com.ecommerce.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("telefoneConverter")
public class TelefoneConverter implements Converter{

	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		return value;
	}

	public String getAsString(FacesContext context, UIComponent component, Object obj) {
	    String valor = null;
	    if(obj instanceof String) {
	        valor = (String) obj;
	        valor = "(" + valor.substring(0, 2) + ") " + valor.substring(2, 6) + "-" + valor.substring(6, valor.length()); 
	    }
	    return valor;
	}
}